<?php
/* SVN FILE: $Id: assignments_controller.php 34 2009-10-17 13:42:12Z kenreily@gmail.com $ */
/**
 * Short description for file.
 *
 * Long description for file
 *
 * PHP versions 4 and 5
 *
 * Recenseo: Online submission and reviewing for education
 * Copyright 2008-2009, Ken Reily
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * $Date: 2009-10-17 13:42:12 +0000 (Sat, 17 Oct 2009) $
 * $Revision: 34 $
 * $Author: kenreily@gmail.com $
 * $HeadURL: http://recenseo.googlecode.com/svn/trunk/app/controllers/assignments_controller.php $
 */
class AssignmentsController extends AppController
{
  var $name = 'Assignments';
  var $helpers = array('Time');
  var $scaffold = 'admin';
  var $uses = array('Assignment','Assessment','AssessmentRating');
  
  function index($course_id)
  {
    $user_id = $this->Session->read('Auth.User.id');

    // Get user info - make sure this user is enrolled in this course.
    $params = 
      array('conditions' => array('User.id' => $user_id));
    $user = $this->User->find('first',$params);
    $this->set('user',$user);

    foreach ($user['Course'] as $course)
    {
      if ($course['id'] == $course_id)
      {
	$this->set('course_id',$course_id);
	$this->pageTitle = $course['name'];
	
	$params = 
	  array('conditions' => array('Course.id' => $course_id),
		'recursive' => 0);
	$assignments = $this->Assignment->find('all',$params);
	$this->set('assignments',$assignments);

	$params = 
	  array('conditions' => array('AssessmentRating.user_id' => $user_id),
		'recursive' => 2);
	$ratings = $this->AssessmentRating->find('all',$params);
	$this->set('ratings',$ratings);
	
	$this->set('asmt_count',$this->Assessment->countForUserCourse($user_id,$course_id));

	break;
      }
    }

    if (!isset($assignments)) 
    {
      $this->Session->setFlash('You are not enrolled in this course.');
    }
  }
}
?>